<style type="text/css">
	table tr td div{ text-align:left !important; margin:0 !important}
	table tr{ vertical-align:top; padding:10px;}
    .error{
        color:red;
        font-size:12px;  
    }
</style>

<script>
$(document).ready(function(){
  $(".drop_btn").click(function(){
    //$(".showbox").toggle();
  });
});
</script>
<style type="text/css" >
@import url('css/bootstrap-tagsinput.css');
</style>

<!-- for lightbox -->
<!--
<script src="js/jquery-1.11.0.min.js"></script>
-->
<script src="js/lightbox.js"></script>
<!-- for lightbox ends-->
	
<script src="js/jquery.validate.min.js"></script>
<script type="text/javascript" src="js/script.js"></script>

<div id="birthday_notification_templates" style="display: none;">
    <div id="birthday_wish_tomorrow">
        <a href="{0}">{1}</a> has birthday tomorrow.
        <a href="{{0}}">Click here</a> to write to his DNA profile. 
    </div>
    <div id="birthday_wish_today">
        <a href="{0}">{1}</a> has birthday today.
        <a href="{0}">Click here</a> to write to his DNA profile. 
    </div>
    <div id="birthday_wish_belated">
        You missed to wish birthday to <a href="{0}">{1}</a> on <strong>{2}</strong>.
        <a href="{0}">Say</a> Belated happy birthday to him. 
    </div>
</div>
<div id="my_updated_cluster" style="display:none">
<?php
$oDropfilters= new CGetFilters();
$clusterDrops=$oDropfilters->getClusters($_SESSION["Allyfolio_User_ID"],1);
$clusterStr='
    <select id="{0}"  name="{0}" {2}>
        <option value="" selected="selected">{1}</option>';
        foreach($clusterDrops as $mycluster){
            $clusterStr.='<option value="'.$mycluster["Cluster_ID"].'" >'.$mycluster["Cluster_Name"].'</option>';
        }
    $clusterStr.='</select>';
echo $clusterStr;
?>
</div>

<div id="toPopup" class="inbox">
    <div class="close"></div>
    <div id="popup_content">  
        <!-- new add location popup as on 24 May, 2015 -->        
        <div class="addLocation">
            <form id="frmlocupdt" name="frmlocupdt" method="post" action="ajax/update_data.php?action=st_location" novalidate="novalidate">
                <p>Add Location</p>
                <textarea id="txtlocation" name="txtlocation" rows="5" cols="10" maxlength="50"></textarea>
                <input type="submit" value="Finish" />
            </form>
        </div>
        <!-- new add location popup as on 24 May, 2015 Ends -->
        
        <!-- new friend request popup as on 09 June, 2015 -->        
        <div class="friendRequestPopup">
            <div id="friendRequestPopupdiv"></div>
        </div>
        <!-- new friend request popup as on 09 June, 2015 Ends -->
        
        <!-- new sharing popup as on 24 May, 2015 -->        
        <div class="newShare">
            <form id="frmshareupdt" name="frmshareupdt" method="post" action="ajax/update_data.php?action=st_share" novalidate="novalidate">
                <input type="hidden" id="post_shared_id" name="post_shared_id" value="0"  />
                <input type="hidden" id="nPostType" name="nPostType" value="0"  />
                
                <div class="shareTop">Share</div>
                <div>
                <?php
                $sharewithDrops=$oDropfilters->getFilters("share_with");
                ?>
                    <select id="share_with_options"  name="share_with_options">
                        <option value="" selected="selected">Share with</option>
                        <?php
                        $defaultSelected=2; //share with type assigned
                        $jsShareWithJson="";
                        foreach($sharewithDrops as $shareWith){
                            if($shareWith["share_dropin_id"]==$defaultSelected){
                                $selected=true;
                            }
                            else if($shareWith["keyword"]=="friends"){
                                $selected=true;
                            }
                            else{
                                $selected=false;
                            }
                            $selected=false;    
                            
                            $jsShareWithJson.=$shareWith["keyword"].":".$shareWith["share_dropin_id"].",";   
                            ?>
                            <option value="<?php echo $shareWith["share_dropin_id"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >
                                <?php echo $shareWith["title"]; ?> 
                            </option>
                            <?php
                        }
                        ?>
                    </select>
                </div>  
                <?php
                //getClusters
                $clusterDrops=$oDropfilters->getClusters($_SESSION["Allyfolio_User_ID"],1);
                ?>
                <div id="myclusters" style="display: none;">
                    <select id="share_with_cluster"  name="share_with_cluster">
                        <option value="" selected="selected">Share with</option>
                        <?php
                        foreach($clusterDrops as $mycluster){    
                            ?>
                            <option value="<?php echo $mycluster["Cluster_ID"] ?>" >
                                <?php echo $mycluster["Cluster_Name"]; ?> 
                            </option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
                <!--<input id="share_with" name="share_with" type="text" placeholder="Abc" />-->
                <textarea id="post_share_msg" name="post_share_msg" placeholder="Write here....." rows="3"></textarea>
                <br />
                <br />
                <br />
                <div id="posttoshare_snapshot">
                    Loading...
                </div>
                <br />
                <br />
                <!--
                <textarea placeholder="" rows="8"></textarea>
                -->
                <p style=" width:100%;">
                    <span>&nbsp;</span>
                    <!--
                    <select id="share_privacy"  name="share_privacy">
                        <option value="" selected="selected">Privacy</option>
                        <option value="1">Own DNA</option>
                        <option value="2">With your friends</option>
                        <option value="3">Cluster</option>
                        <option value="4">Through message</option>
                        <option value="5">Family</option>
                    </select>
                    
                    <input type="submit" value="Privacy" />
                    -->  
                    <input type="submit" value="Cancel" />  
                    <input type="submit" value="Share Now" /> 
                </p>
            </form>
        </div>
        <!-- new sharing popup as on 24 May, 2015 ENds-->
        
        <!-- new create clusters -->
        <div class="createcluster">
            <form id="frmcreatecluster" name="frmcreatecluster" method="post" action="ajax/generic_crudoperations.php" novalidate="novalidate">
                <strong>Create Cluster</strong>
                <table style="width: 400px;" cellpadding="5px">
                    <tr>
                        <td style="font-weight: bold;">
                            Enter Cluster Name
                        </td>
                        <td>
                            :
                        </td>
                        <td>
                            <input type="text" id="txtclustername" name="txtclustername" />
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3"></td>
                    </tr>
                    <tr>
                        <td colspan="2"></td>
                        <td>
                            <input type="submit" value="Save" />
                        </td>
                    </tr>
                </table>
            </form>
        </div>
        <!-- new create clusters ends -->
        
        <!-- new add cluster friends popup -->
        <div id="clusters_div" class="clusterWrapper">
            <form id="frmAddcluster" name="frmAddcluster" >
                <input type="hidden" id="hClusterid" name="hClusterid" value="0" />
                <div class="cluster">
                    <!-- box 1 -->
                    <div class="clusterBox">
                        <h3 id="clusterName">Unknown</h3>
                        <div class="clusterBoxIn">
                            <!--
                            <div class="tpInput">
                                <input type="text" placeholder="Cluster Name" />
                            </div>
                            -->
                            <div class="tpInput2">
                                <input type="text" id="txtclusterfname" placeholder="Enter Name" /> 
                                <input type="hidden" id="hidclusterfrnds" name="hidclusterfrnds" />
                                <div style="text-align: right;">
                                <br />
                                <input type="button" value="Add" onclick="return addclusterFriend();" />
                                </div>
                            </div>
                            <div class="uBox">
                                <!--
                                <ul id="cluster_">                                
                                    <li>
                                        <div class="frm"></div> 
                                        <div class="txt">
                                            <h4>Abc</h4>
                                            <p>New Delhi</p>
                                            <p>India</p>
                                        </div>
                                        <div class="crx">
                                            <a href="#"><img src="images/cross.png"/></a>
                                        </div>
                                    </li>
                                </ul>
                                -->
                            </div>
                        </div>
                    </div>
                    <!-- box 2 -->
                    <!--
                    <div class="clusterBox">
                        <h3>c2</h3>
                        <div class="clusterBoxIn">
                            <div class="tpInput">
                                <input type="text" placeholder="Cluster Name" />
                            </div>
                            <div class="tpInput2">
                                <input type="text" placeholder="Enter Name" /> 
                                <input type="submit" value="Add" />
                            </div>
                            <div class="uBox">
                                <ul>
                                    <li>
                                        <div class="frm"></div> 
                                        <div class="txt">
                                            <h4>Abc</h4>
                                            <p>New Delhi</p>
                                            <p>India</p>
                                        </div>
                                        <div class="crx">
                                            <a href="#"><img src="images/cross.png"/></a>
                                        </div>
                                    </li>
                                    <li>
                                        <div class="frm"></div> 
                                        <div class="txt">
                                            <h4>Abc</h4>
                                            <p>New Delhi</p>
                                            <p>India</p>
                                        </div>
                                        <div class="crx">
                                            <a href="#"><img src="images/cross.png"/></a>
                                        </div>
                                    </li>
                                </ul>
                            </div>
                        </div>
                    </div>   
                     box 2 ends -->             
                </div>
            </form>
        </div>
        <!-- new add cluster friends popup ends here-->
    </div>
</div>


<!-- privacy setting -->
<div id="popup"><span class="button b-close">X</span> 
    <div id="idchangefeedprivacy">
        <form id="frmupdtfeedprivacy" name="frmupdtfeedprivacy" method="post" action="ajax/update_data.php?action=st_updatefeedprivacy" novalidate="novalidate">
            <input type="hidden" id="post_id_for_privacy" name="post_id_for_privacy" value="0"  />
            <input type="hidden" id="nPostType" name="nPostType" value="0"  />
            
            <div class="newStatusPrivacy">
                <div class="topSel">
                    <strong>Show only</strong>
                    <?php
                    $jsonPrivacyTypes="";
                    $privacyTypes=$oDropfilters->getFilters("privacy_types");
                    ?>  
                    <select id="prvsetforthispost" id="prvsetforthispost" >
                        <?php
                        $myprivacysetting=0;
                        if (!empty($_SESSION['user_settings']['privacy_settings'])) {
                            $myprivacysetting = trim($_SESSION['user_settings']['privacy_settings']);
                        }
                        if(is_numeric($myprivacysetting) && $myprivacysetting>0){
                            $defaultSelected=$myprivacysetting;
                        }
                        else{
                            $defaultSelected=1; //privacy type assigned    
                        }
                        foreach($privacyTypes as $privacyType){
                            if($privacyType["ID"]==$defaultSelected){
                                $selected=true;
                            }
                            else if($privacyType["keyword"]=="public"){
                                $selected=true;
                            }
                            else{
                                $selected=false;
                            }
                                
                            $jsonPrivacyTypes.=$privacyType["keyword"].":".$privacyType["ID"].",";    
                            ?>
                            <option value="<?php echo $privacyType["ID"] ?>" <?php if($selected){  ?>selected="true" <?php } ?> >
                                <?php echo $privacyType["Privacy_Type_Title"]; ?> 
                            </option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
                <?php
                //getClusters
                $clusterDrops=$oDropfilters->getClusters($_SESSION["Allyfolio_User_ID"],1);
                ?>
                <div id="myclustersprivacy" style="display: none;">
                    <select id="show_with_cluster"  name="show_with_cluster">
                        <option value="" selected="selected">Show with</option>
                        <?php
                        foreach($clusterDrops as $mycluster){    
                            ?>
                            <option value="<?php echo $mycluster["Cluster_ID"] ?>" >
                                <?php echo $mycluster["Cluster_Name"]; ?> 
                            </option>
                            <?php
                        }
                        ?>
                    </select>
                </div>
                <br />
                <br />
                <p><strong>Show for specific person</strong></p>    
                <input type="text" id="txtSpecificPerson" name="Specific_Friends_ID" placeholder="Type Name"  />
                
                <input type="hidden" id="userfriendids" name="userfriendids" />
                <input type="hidden" id="alluserfriendids" name="alluserfriendids" />
                
                <p><strong>Don't show for specific person</strong></p>    
                <input id="txtNotSpecificPerson" type="text" placeholder="Enter name..." />
                <input type="hidden" id="ignoreduserfriendids" name="ignoreduserfriendids" />
                <input type="hidden" id="totalids" name="totalids" value="" />
                
                <br/>
                <br/>
                <input type="button" name="cmdSavePostPrivacy" id="cmdSavePostPrivacy" value="Save Settings"  onclick="setPrivacySettingForPost('frmupdtfeedprivacy');"/>
            </div>
        </form>
    </div>
</div>

<!-- loader and BG effect -->
<div class="loader"></div>
<div id="backgroundPopup"></div>

<div id="load_htmls"></div>

<!--STARTs for privacy setting popup -->
<script src="js/jquery.bpopup.js"></script> 
<script src="js/scripting.min.js"></script> 
<script src="js/jquery.easing.1.3.js"></script> 
<!--ENDS for privacy setting -->

<!--
<script src="js/typeahead.bundle.js"></script>

<script src="js/typeahead-css.js"></script>
-->

<script>

<?php
if(strlen($jsShareWithJson)>1){
    $jsShareWithJson=substr($jsShareWithJson,0,strlen($jsShareWithJson)-1);
}
else{
    $jsShareWithJson="error:0";
}

if(strlen($jsonPrivacyTypes)>1){
    $jsonPrivacyTypes=substr($jsonPrivacyTypes,0,strlen($jsonPrivacyTypes)-1);
}
else{
    $jsonPrivacyTypes="error:0";
}

?>
var sharewithtags={<?php echo $jsShareWithJson; ?>};
var jsprivacytypes={<?php echo $jsonPrivacyTypes; ?>};

// HTML templates
function showClusterFList(clusterId,clustername,isShowClusterName){
    var clusterBoxT='<ul id="cluster_{0}">{1}</ul>';
    var clusterFriendT='<li id="cFrnd_{1}" style="width:200px!important"><table><tr><td style="text-align:left"><div class="frm">{5}</div></td><td style="text-align:left"><table><tr><td style="text-align:left"><b>{2}</b></td></tr><tr><td style="text-align:left">{3}</td></tr><tr><td style="text-align:left">{4}</td></tr></table></td><td style="padding-left:5px"><div onclick="return removeClusterFriend({0},{1});"><img src="images/cross.png"/></div></td></tr></table></li>';
    
    var clusterFriendsDataStr=''; 
    $.ajax({
	  	type: "POST",
	  	url: "ajax/getAjaxHtml.php",
	  	cache: false,
        async:false,
	  	data: { actiontype:'show_clusters_friends_for_popup',clusterid:clusterId}
	})
	.done(function( msg ) {	
	   //alert(msg);
       if(msg.search("{")>0){
            //It is JSON
          //for loop
          var clusterJsonFriends=$.parseJSON(msg);
            var jsonFriend={};
            var linkT='<a href="{0}">{1}</a>';
            var fname='';
            var fimg='';
            if(clusterJsonFriends!=null){
                for(var jsonFriendL in clusterJsonFriends ){
                    //a.hasOwnProperty(key)
                    jsonFriend=clusterJsonFriends[jsonFriendL];
                    fname=linkT.format(jsonFriend.ulink,jsonFriend.uname);
                    fimg=linkT.format(jsonFriend.ulink,'<img src="{0}" width="62"></img>'.format(jsonFriend.upicpath));
                    
                    clusterFriendsDataStr+=clusterFriendT.format(clusterId,jsonFriend.uid,fname,jsonFriend.city,jsonFriend.country,fimg);
                }
                clusterBoxT=clusterBoxT.format(clusterId,clusterFriendsDataStr);
                
                if(clusterJsonFriends.length>0){
                    $(".uBox").html(clusterBoxT);
                    if(isShowClusterName){
                        $("#clusterName").html(clustername);
                    }
                    loadPopupClass(commonpopus.clusterWrapper,clusterId);
                }
            }
            else{
                $(".uBox").html("Some issue occurred");
            }
       }
	   else{
	       //the response was something else
            $(".uBox").html(msg);
            if(isShowClusterName){
                $("#clusterName").html(clustername);
            }
            loadPopupClass(commonpopus.clusterWrapper,clusterId);
	   	       
	   }
		  
    })
    .fail(function(msg) {
	   
	})
    .always(function() {
        
	});
    
} 



function addclusterFriend(){
    var clusterId=0;
    var friendIds='';
    if($("form#frmAddcluster").find("#hClusterid")){
        clusterId=$("form#frmAddcluster").find("#hClusterid").val();    
    }
    if(!isNaN(clusterId) && clusterId>0){
        if($("form#frmAddcluster").find("#hidclusterfrnds")){
            friendIds=$("form#frmAddcluster").find("#hidclusterfrnds").val();  
            ajaxAddClusterFriendAjax(clusterId,friendIds);  
        }
    }
    
} 

function ajaxAddClusterFriendAjax(clusterID,friendsId){
    $.ajax({
	  	type: "POST",
	  	url: "ajax/generic_crudoperations.php",
	  	cache: false,
	  	data: { actiontype:'add_cluster_friend',clusterid:clusterID,friendsid:friendsId}
	})
	.done(function( msg ) {
	   //alert(msg);
	   var jsonParsed=$.parseJSON(msg);
       if(!isNaN(jsonParsed.err)){ //means have some code
            switch(parseInt(jsonParsed.err)){
                case 200:
                        alert(jsonParsed.msg);
                        showClusterFList(clusterID,'',false);
                        break;
                case 202:
                        alert(jsonParsed.msg);
                        break;
                default:
                        alert(jsonParsed.msg);
                        break;
            }
        }
    })
    .fail(function(msg) {
	   
	})
    .always(function() {
        
	});
}

function removeClusterFriend(clusterId, idClusterFriend){
    //alert("remove - cluster id: "+clusterId+" add friendID: "+idClusterFriend);
    $.ajax({
	  	type: "POST",
	  	url: "ajax/generic_crudoperations.php",
	  	cache: false,
	  	data: { actiontype:'remove_cluster_friend',clusterid:clusterId,friendsid:idClusterFriend}
	})
	.done(function( msg ) {
	   //alert(msg);
	   var jsonParsed=$.parseJSON(msg);
       if(!isNaN(jsonParsed.err)){ //means have some code
            switch(parseInt(jsonParsed.err)){
                case 200:
                        alert(jsonParsed.msg);
                        $(".uBox #cluster_"+clusterId+" #cFrnd_"+idClusterFriend).remove();
                        break;
                case 202:
                        alert(jsonParsed.msg);
                        break;
                default:
                        alert(jsonParsed.msg);
                        break;
            }
        }
    })
    .fail(function(msg) {
	   
	})
    .always(function() {
        
	});
    
}

function setPrivacySettingForPost(frmname){   
    var postid=0;
    var privacytypeid=0;
    if(document.forms[frmname].elements["post_id_for_privacy"]){
        postid=document.forms[frmname].elements["post_id_for_privacy"].value;    
    }
    privacytypeid=(isNaN(document.getElementById("prvsetforthispost").value)?0:document.getElementById("prvsetforthispost").value);
    var clusteridsel=(isNaN(document.getElementById("show_with_cluster").value)?0:document.getElementById("show_with_cluster").value);
    var allowedfrnds=document.getElementById('userfriendids').value;
    var ignfrnds=document.getElementById('ignoreduserfriendids').value ;
    var jsondata={feedid:postid,privacytype:privacytypeid,clusterid:clusteridsel,allowedFriends:allowedfrnds,ignoredFriends:ignfrnds};
    //prvsetforthispost jsprivacytypes
    uFeedPSet(frmname,jsondata);
}


$("#frmshareupdt #share_with").hide();
/* event for close the popup */
	$(".close").hover(
		function() {
			$('.ecs_tooltip').show();
		},
		function () {
			$('.ecs_tooltip').hide();
		}
	);
	
	$(".close").click(function() {
		disablePopup();  // function close pop up
	});
	
	$(this).keyup(function(event) {
		if (event.which == 27) { // 27 is 'Ecs' in the keyboard
			disablePopup();  // function close pop up
		}  	
	});
	
	$("#backgroundPopup").click(function() {
		disablePopup();  // function close pop up
	});

    $("#share_with_options").change(function(){
       var sharedWithval= $("#share_with_options").val();
       
       if(sharedWithval==sharewithtags.cluster){
            $("#frmshareupdt #myclusters").show();
       }
       else{
            $("#frmshareupdt #myclusters").hide();
       }
    });
    
    $("#prvsetforthispost").change(function(){
       var showWithval= $("#prvsetforthispost").val();
       
       if(showWithval==jsprivacytypes.choose_cluster){
            $("#frmupdtfeedprivacy #myclustersprivacy").show();
       }
       else{
            $("#frmupdtfeedprivacy #myclustersprivacy").hide();
       }
    });
var locationmaxLength=120;    
//validate location form    
$("#frmlocupdt").validate({
    
    // Specify the validation rules
    rules: {
        txtlocation:{
            required:true,
            maxlength:locationmaxLength   
        }
    },
    
    // Specify the validation error messages
    messages: {
        txtlocation: {
            required: "Please provide your location",
            minlength: "Please enter your location in a limit of "+locationmaxLength+" characters"
        }
    },
    
    submitHandler: function(form) {
        //form.submit();
        //do your stuff
        $( "#frmstupdt #locstr" ).val($( "#frmlocupdt #txtlocation" ).val());
        $( "#frmstupdt #post_location" ).html("&nbsp;Location: near to \""+$( "#frmlocupdt #txtlocation" ).val().trim()+"\"");
        $( "#frmstupdt #post_location" ).show();
        $("#ajx_status_update").focus();
        
        //$( "#frmlocupdt txtlocation" ).val("");        
        disablePopup();  // function close pop up
    }
});
  
$("#frmshareupdt").validate({
    // Specify the validation rules
    rules: {
        share_with_options: "required",
        share_with_cluster: "required"
    },
    
    // Specify the validation error messages
    messages: {
        share_with_options: "<p style='padding-bottom:5px'>* Please select the option for sharing</p>",
        share_with_cluster: "<p style='padding-bottom:5px'>* Please select one of the cluster for sharing</p>"
    },
    
    submitHandler: function(form) {
        if(document.getElementById("nPostType")){
            document.getElementById("nPostType").value=postactiontype.share_post;
        }
        ust('frmshareupdt');
        /*if($("#frmshareupdt").find("#share_with")){
            if($("#frmshareupdt #share_with").css("display")!="none"){
                if($("#frmshareupdt #share_with").val().trim().length<=0){
                    if($("#frmshareupdt ").find("#share_with_err")){
                            
                    }
                    else{
                        $("#frmshareupdt #share_with").append("<p id='share_with_err' style='padding-bottom:5px'>* Please enter cluster name</p>");
                    }
                    return false;
                }
                else{
                    $("#frmshareupdt").find("#share_with_err").remove();
                }
            }
        }
        */
        //form.submit();
    }
});


  
$("#frmcreatecluster").validate({
    // Specify the validation rules
    rules: {
        txtclustername: "required"
    },
    
    // Specify the validation error messages
    messages: {
        txtclustername: "<p style='padding-bottom:5px'>* Please enter cluster name</p>"
    },
    
    submitHandler: function(form) {
        if(document.getElementById("nPostType")){
            document.getElementById("nPostType").value=postactiontype.share_post;
        }
        fCreateCluster('frmcreatecluster');
        //form.submit();
    }
});


/*
$("#frmshareupdt").validate({
        // Specify the validation rules
        rules: {
            firstname: "required",
            lastname: "required",
            email: {
                required: true,
                email: true
            },
            password: {
                required: true,
                minlength: 5
            },
            agree: "required"
        },
        
        // Specify the validation error messages
        messages: {
            firstname: "Please enter your first name",
            lastname: "Please enter your last name",
            password: {
                required: "Please provide a password",
                minlength: "Your password must be at least 5 characters long"
            },
            email: "Please enter a valid email address",
            agree: "Please accept our policy"
        },
        
        submitHandler: function(form) {
            form.submit();
        }
    });*/
    
    
/*
function getUsersjsonList(){
    var uJson=[{ "value": 1 , "text": "Amsterdam"  },{ "value": 1 , "text": "Test"  }];
    //$.getJSON('cities.json');
    return uJson;
}

$.getScript('js/bootstrap-tagsinput.js',function(){
    
    $('#txtSpecificPerson').tagsinput({
      tagClass: function(item) {
        switch (item.continent) {
          case 'Europe'   : return 'label label-info';
          case 'America'  : return 'label label-important';
          case 'Australia': return 'label label-success';
          case 'Africa'   : return 'badge badge-inverse';
          case 'Asia'     : return 'badge badge-warning';
        }
      },
      maxTags: 3, //he given number of tags are allowed to add (default: undefined)
      confirmKeys: [13, 44], //Array of keycodes which will add a tag when typing in the input. (default: [13], which is ENTER)
      itemValue: 'value',
      itemText: 'text',
      typeahead: {
        source: function(query) {
          return getUsersjsonList();
        }
      },
      onTagExists: function(item, $tag) {        
       // $tag.hide.fadeIn();
      }
    });
    
    $('#txtNotSpecificPerson').tagsinput({
      itemValue: 'value',
      itemText: 'text',
      typeahead: {
        source: function(query) {
          return getUsersjsonList();
        }
      }
    });
});

*/
</script>
<script>
   var totalids=""; 
   var idtoAdd="";
   var idnottoAdd="";
   var ms5=null;
   
    $(document).ready(function() {
        $.noConflict();
        
        
        ms5 = $('#txtSpecificPerson').magicSuggest({
            width: 300,
            value: '',
            id: 'userfriendids',
            data: 'ajax_search/suggestusers.php',
            dataUrlParams: {
                init: 1,
                oldids: $("#totalids").val()
            }
        });
        
         $(ms5).on('selectionchange', function(){
              var ids=JSON.stringify(this.getValue());
              idtoAdd=(((ids.replace('["','')).replace('"]','')).replace(',"',',')).replace('",',',');
              idtoAdd=idtoAdd.replace(",[]","");
              idtoAdd=idtoAdd.replace("[],","");
              idtoAdd=idtoAdd.replace("[]","");
              var oldidsval=idtoAdd+","+idnottoAdd;
              oldidsval=oldidsval.replace("[],[]",'');
              oldidsval=oldidsval.replace("[],",'');
              oldidsval=oldidsval.replace(",[]",'');
              oldidsval=oldidsval.replace("[]",'');
              if(oldidsval==',')
              {
                oldidsval='';
              }
              
              $("#totalids").val(oldidsval);
              
              
              if(!ifFriendIsAlreadyPicked("allow",this.getValue())){
                //alert("include friend list: "+this.getValue());
                allowToaddInselection=true;
                document.getElementById('userfriendids').value=idtoAdd;  
                
                
              }
              else{
                allowToaddInselection=false;
                alert("friend is added in non - specific list");
              }
              
              //document.getElementById('userfriendids').value=(((ids.replace('["','')).replace('"]','')).replace(',"',',')).replace('",',',');
              
            });
            
            $(ms5).on('beforeload', function(c){
                //ms5.setDataUrlParams({defaultValues: $("#totalids").val()});
                ms5.setDataUrlParams({
                    init: 1,
                    oldids: $("#totalids").val(),
                    mstime: new Date().getTime()
                });
                
                //console.debug(this);
            });
            
            
        var ms51 = $('#txtNotSpecificPerson').magicSuggest({
            width: 300,
            value: '',
            id: 'ignoreduserfriendids',
            data: 'ajax_search/suggestusers.php',
            dataUrlParams: {
                init: 1,
                defaultValues: $("#totalids").val()
            }  
        });
                             
         $(ms51).on('selectionchange', function(){
              var ids=JSON.stringify(this.getValue());
              idnottoAdd=(((ids.replace('["','')).replace('"]','')).replace(',"',',')).replace('",',',');
              idnottoAdd=idnottoAdd.replace(",[]","");
              idnottoAdd=idnottoAdd.replace("[],","");
              idnottoAdd=idnottoAdd.replace("[]","");
              var oldidsval=idtoAdd+","+idnottoAdd;
              oldidsval=oldidsval.replace("[],[]",'');
              oldidsval=oldidsval.replace("[],",'');
              oldidsval=oldidsval.replace(",[]",'');
              oldidsval=oldidsval.replace("[]",'');
              if(oldidsval==',')
              {
                oldidsval='';
              }
              $("#totalids").val(oldidsval);
              
              if(!ifFriendIsAlreadyPicked("deny",this.getValue())){
                //alert("ignore friend list: "+this.getValue());
                allowToaddInselection=true;
                document.getElementById('ignoreduserfriendids').value=idnottoAdd;  
              }
              else{
                allowToaddInselection=false;
                alert("friend is added in specific list");
              }
         });
         $(ms51).on('beforeload', function(c){
                //ms5.setDataUrlParams({defaultValues: $("#totalids").val()});
                ms51.setDataUrlParams({
                    init: 1,
                    oldids: $("#totalids").val(),
                    mstime: new Date().getTime()
                });
                //console.debug(this);
            });
            
         var ms52 = $('#st_taggedusers').magicSuggest({
            /*width: 300,*/
            value: '',
            id: 'sttaggedusers',
            data: 'ajax_search/suggestusers.php' 
        });
        
         $(ms52).on('selectionchange', function(){
              var ids=JSON.stringify(this.getValue());
              var idtoAdd=(((ids.replace('["','')).replace('"]','')).replace(',"',',')).replace('",',',');
              document.getElementById('sttaggedusers').value=idtoAdd;
              
         }); 
         
         var mscluster = $('#txtclusterfname').magicSuggest({
            /*width: 300,*/
            value: '',
            id: 'hidclusterfrnds',
            data: 'ajax_search/suggestusers.php' 
        });
        
         $(mscluster).on('selectionchange', function(){
              var ids=JSON.stringify(this.getValue());
              var idtoAdd=(((ids.replace('["','')).replace('"]','')).replace(',"',',')).replace('",',',');
              document.getElementById('hidclusterfrnds').value=idtoAdd;
              
         });    
    });
    
    function ifFriendIsAlreadyPicked(sourceid,fid){
        switch(sourceid){
            case "allow":
                //check if user is selected in deny list
                var selectedUserList="";
                if(document.getElementById("ignoreduserfriendids")){
                    selectedUserList=document.getElementById("ignoreduserfriendids").value;
                    var selectedFidarr="";
                    if(selectedUserList.search(",")>0){
                        selectedFidarr=selectedUserList.split(",");
                        if(selectedFidarr.indexOf(fid)>0){
                            return true;
                        }
                    }
                }
                break;
            case "deny":
                //check if user is selected in allow list
                var selectedUserList="";
                if(document.getElementById("userfriendids")){
                    selectedUserList=document.getElementById("userfriendids").value;
                    var selectedFidarr="";
                    if(selectedUserList.search(",")>0){
                        selectedFidarr=selectedUserList.split(",");
                        if(selectedFidarr.indexOf(fid)>0){
                            return true;
                        }
                    }
                }
                break;
        }
        return false;
        
    }
    
    function reportThisPost(postChkHideid){
        if(document.getElementById(postChkHideid)){
            //alert(document.getElementById(postChkHideid).checked);
            var isMarkedHidden=document.getElementById(postChkHideid).checked;
            if(document.getElementById(postChkHideid).checked==true){
                document.getElementById(postChkHideid).checked=false;
            }
            else{
                document.getElementById(postChkHideid).checked=true;
            }
            var postid=postChkHideid.replace("hid_rpt_","");
            //alert(postid);
            if(isMarkedHidden==true){
                $("#isPostHide_"+postid).html("Show");
            }
            else{
                $("#isPostHide_"+postid).html("Hide");
            }
        }
    }
    </script>